package monitoringMod.controller;

import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import monitoringMod.service.MonitoringModService;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import ttp.to.ChemicalTO;
import ttp.to.CrushTO;
import ttp.to.CuttingTO;
import ttp.to.DryingTO;
import ttp.to.TreeTO;

public class MonitoringController extends MultiActionController {
	private MonitoringModService monitoringService;
	
	public void setMonitoringModService(MonitoringModService monitoringService){
		this.monitoringService = monitoringService;
	}
	//tree 전체 검색
	public ModelAndView selectMonitoringAllSuccessTree(HttpServletRequest request, HttpServletResponse respone){
		ModelAndView mav = null;
		HashMap map = new HashMap();
		String enterprise1 = request.getParameter("enterprise1");
		String enterprise2 = request.getParameter("enterprise2");
		String enterprise3 = request.getParameter("enterprise3");
		int Atree = 0;
		int Btree = 0;
		int Ctree = 0;
		try {
			List<TreeTO> AllListTree = monitoringService.selectAllSuccessTree(1);
			Atree = monitoringService.treeCountMonitoringEnterprise(enterprise1);
			Btree = monitoringService.treeCountMonitoringEnterprise(enterprise2);
			Ctree = monitoringService.treeCountMonitoringEnterprise(enterprise3);
			map.put("Atree", Atree);
			map.put("Btree", Btree);
			map.put("Ctree", Ctree);
			map.put("AllListTree", AllListTree);
			return mav = new ModelAndView("jsonView", "map_list", map);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return mav;
	}
	
	//p1 전체 검색
	public ModelAndView selectMonitoringAllSuccessCrush(HttpServletRequest request, HttpServletResponse response){
		ModelAndView mav = null;
		try {
			List<TreeTO> AllListTree = monitoringService.selectAllSuccessTree(1);
			List<CrushTO> AllList1 = monitoringService.selectAllSuccessCrush(1);
			HashMap map = new HashMap();
			map.put("AllListTree", AllListTree);
			map.put("AllList1", AllList1);
			return mav = new ModelAndView("jsonView","map_list",map);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return mav;
  }
	
	//p2 전체 검색
	public ModelAndView selectMonitoringAllSuccessChemical(HttpServletRequest request, HttpServletResponse response){
		ModelAndView mav = null;
		try {
			List<CrushTO> AllList1 = monitoringService.selectAllSuccessCrush(1);
			List<ChemicalTO> AllList2 = monitoringService.selectAllSuccessChemical(1);
			HashMap map = new HashMap();
			map.put("AllList1", AllList1);
			map.put("AllList2", AllList2);
			return mav = new ModelAndView("jsonView", "map_list", map);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return mav;
  }
		
	//p3 전체 검색
	public ModelAndView selectMonitoringAllSuccessDrying(HttpServletRequest request, HttpServletResponse response){
		ModelAndView mav = null;
		try {
			List<ChemicalTO> AllList2 = monitoringService.selectAllSuccessChemical(1);
			List<DryingTO> AllList3 = monitoringService.selectAllSuccessDrying(1);
			HashMap map = new HashMap();
			map.put("AllList2", AllList2);
			map.put("AllList3", AllList3);
			return mav = new ModelAndView("jsonView", "map_list", map);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return mav;
  }
			
	//p4 전체 검색
	public ModelAndView selectMonitoringAllSuccessCutting(HttpServletRequest request, HttpServletResponse response){
		ModelAndView mav = null;
		try {
			List<DryingTO> AllList3 = monitoringService.selectAllSuccessDrying(1);
			List<CuttingTO> AllList4 = monitoringService.selectAllSuccessCutting(0);
			HashMap map = new HashMap();
			map.put("AllList3", AllList3);
			map.put("AllList4", AllList4);
			return mav = new ModelAndView("jsonView", "map_list", map);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return mav;
  }
				
	public ModelAndView treeCountMonitoringEnterprise(HttpServletRequest request, HttpServletResponse respone){
		  ModelAndView mav = null;
		  HashMap map = new HashMap();
		  String enterprise1 = request.getParameter("enterprise1");
		  String enterprise2 = request.getParameter("enterprise2");
		  String enterprise3 = request.getParameter("enterprise3");
		  int Atree = 0;
		  int Btree = 0;
		  int Ctree = 0;
		  
		  try {
		   Atree = monitoringService.treeCountMonitoringEnterprise(enterprise1);
		   Btree = monitoringService.treeCountMonitoringEnterprise(enterprise2);
		   Ctree = monitoringService.treeCountMonitoringEnterprise(enterprise3);
		   map.put("Atree", Atree);
		   map.put("Btree", Btree);
		   map.put("Ctree", Ctree);
		   mav = new ModelAndView("jsonView","tree",map);
		   
		  } catch (Exception e) {
		   e.printStackTrace();
		  }
		  
		  return mav;
		 }
		 public ModelAndView paperCountMonitoringEnterprise(HttpServletRequest request, HttpServletResponse respone){
		  ModelAndView mav = null;
		  HashMap map = new HashMap();
		  String enterprise1 = request.getParameter("enterprise1");
		  String enterprise2 = request.getParameter("enterprise2");
		  String enterprise3 = request.getParameter("enterprise3");
		  int Apaper = 0;
		  int Bpaper = 0;
		  int Cpaper = 0;
		  try {
		   Apaper = monitoringService.paperCountMonitoringEnterprise(enterprise1);
		   Bpaper = monitoringService.paperCountMonitoringEnterprise(enterprise2);
		   Cpaper = monitoringService.paperCountMonitoringEnterprise(enterprise3);
		   map.put("Apaper", Apaper);
		   map.put("Bpaper", Bpaper);
		   map.put("Cpaper", Cpaper);
		   
		   mav = new ModelAndView("jsonView","paper",map);
		  } catch (Exception e) {
		   e.printStackTrace();
		  }
		  
		  return mav;
		 }
	
		 public ModelAndView treePerPageCountMonitoringTreeType(HttpServletRequest request, HttpServletResponse respone){
			  ModelAndView mav = null;
			  HashMap map = new HashMap();
			  String treeType1 = request.getParameter("treeType1");
			  String treeType2 = request.getParameter("treeType2");
			  String treeType3 = request.getParameter("treeType3");
			  int AtreeType = 0;
			  int BtreeType = 0;
			  int CtreeType = 0;
			  
			  try{
				  AtreeType = monitoringService.treePerPageCountMonitoringTreeType(treeType1);
				  BtreeType = monitoringService.treePerPageCountMonitoringTreeType(treeType2);
				  CtreeType = monitoringService.treePerPageCountMonitoringTreeType(treeType3);
				  map.put("AtreeType", AtreeType);
				  map.put("BtreeType", BtreeType);
				  map.put("CtreeType", CtreeType);
				  
				  mav = new ModelAndView("jsonView","treePerPage",map);
			  }catch(Exception e){
				  e.printStackTrace();
			  }
			  
			  return mav;
		 }
}

